<?php
namespace App\Http\Middleware;

use Closure;
use Auth;

class WebLogin
{

	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next)
	{
        if (Auth::client()->guest())
        {
            if ($request->ajax() || $request->wantsJson())
            {
                return response()->json([
                    'status' => 401,
                    'message' => 'Unauthorized',
                    'data' => (object) null
                ]);
            }
            else
            {
//                return response('请先登录!', 401);
            }
        }

		return $next($request);
	}
}
